/****** Object:  StoredProcedure [dbo].[Resource_R_ByName]    Script Date: 07/25/2012 23:53:38 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

create PROCEDURE [dbo].[Resource_R_ByName]
    @Start INT ,
    @Limit INT,
	@Name NVARCHAR(200)
AS

	SET NOCOUNT ON;	
	
	
	
	--Select con Filtros
	SELECT 
	    id,
	    ISNULL(nombre,'')+' '+ ISNULL(apellidoPaterno,'') + ' '+ISNULL(apellidoMaterno,'') AS nombre,	    
		ROW_NUMBER() OVER (ORDER BY [nombre] )AS RowNumber 
		INTO #Recurso
	 FROM [Recurso]
	 where 
	      ((ISNULL(nombre,'')+' '+ ISNULL(apellidoPaterno,'') + ' '+ISNULL(apellidoMaterno,''))  like '%' + @Name +'%' or @Name = '')
	 
	
	SELECT COUNT(id) AS ToltalReg FROM #Recurso
	
	SELECT 
	    Id,
	    nombre
	 FROM #Recurso	 	 
	WHERE RowNumber BETWEEN @Start AND (@Start + @Limit)
	
	
	DROP TABLE #Recurso
	
	SET NOCOUNT OFF;
GO


